package it.side.messaging.client;

import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;

/**
 * Evento scatenato all'arrivo di un messaggio
 * @author Simone Masoni
 */
public class MessageEvent extends GwtEvent<MessageEvent.Handler> {

	public interface Handler extends EventHandler {
		void onMessageReceived(Message message);
	}

	/**
	 * A singleton instance of Type&lt;Handler&gt;.
	 */
	public static final Type<Handler> TYPE = new Type<Handler>();
	  
	
	private Message message;
	
	public MessageEvent(Message message) {
		super();
		this.message = message;
	}

	@Override
	public Type<Handler> getAssociatedType() {
		return TYPE;
	}

	@Override
	protected void dispatch(Handler handler) {
		handler.onMessageReceived(message);
	}

	public Message getMessage() {
		return message;
	}

}
